// 05-dog.js
const Event = require('events');

class Dog extends Event {
  constructor(name, energy) {
    super();
    this.#name = name;
    this.#energy = energy;
    this.#star();
  }

  get name() { return this.#name }
  get energy() { return this.#energy }
  set energy(e) {
    this.#energy = e;
    this.#star();
  }

  #star() {
    let timer = setInterval(() => {
      this.emit('bark', this);
      this.#energy--;
      if (this.#energy === 0) {
        clearInterval(timer);
      }
    }, 1000);
  }
  #name = '';
  #energy = 0;

}

module.exports = Dog;